#include<iostream>
using namespace std;

struct student
{
	char sex;
	union
	{
		float run;
		int rope;
	}score;
};

// 输入数据
void input(student s[], int n)
{
	for (int i = 0; i < n; i++)
	{
		cout << "Please input gender(m，f): ";
		cin >> s[i].sex;
		if (s[i].sex == 'm')
		{
			cout << "请输入男生的百米成绩: ";
			cin >> s[i].score.run;
		}
		else if (s[i].sex == 'f')
		{
			cout << "请输入女生的跳绳成绩: ";
			cin >> s[i].score.rope;
		}
		else cout << "非法数据\n";
	}
}

// 输出数据
void output(student s[], int n)
{
	for (int i = 0; i < n; i++)
		if (s[i].sex == 'm')
			cout << "\n男生百米成绩：" << s[i].score.run;
		else if (s[i].sex == 'f')
			cout << "\n女生跳绳成绩：" << s[i].score.rope;
		else cout << "\n非法数据\n";
}

int main()
{
	cout << endl
		 << "学号：3170608043，姓名：石英钰" << endl
		 << endl
		 << "【课件第5章构造数据类型】学生体能测试，男生测100米，女生测跳绳。要求输入学生的体能测试数据并输出。要求利用联合" << endl
		 << endl;
	const int n = 4;
	student s[n];
	input(s, n);
	output(s, n);
	cout << endl;
	return 0;
}